import httpInstance from "@/utils/http";

export const userRegisterAPI = ({ username, password }) => {
    return httpInstance({
        url: '/user/register',
        method: 'post',
        params: {
            username,
            password
        }
    })
}

export function userLoginAPI({ username, password }) {
    return httpInstance({
        url: '/user/login',
        method: 'POST',
        params: {
            username,
            password
        }
    })
}

//获取用户地址
export function useUserAddressAPI() {
    return httpInstance({
        url: '/user/getAddress'
    })
}

//增加地址
export function useInsertUserAddressAPI(data) {
    return httpInstance({
        url: '/user/insertAddress',
        method: 'POST',
        data
    })
}
//删除地址
export function useDeleteAddressAPI(id) {
    return httpInstance({
        url: '/user/deleteAddress',
        params:{
            id
        }
    })
}
//修改地址
export function useUpdateAddressAPI(data) {
    return httpInstance({
        url: '/user/updateAddress',
        method: 'POST',
        data
    })
}
export function useDefaultAddressAPI(id) {
    return httpInstance({
        url: '/user/defaultAddress',
        params:{
            id
        }
    })
}


//修改用户信息
export function useUpdateUserAPI(data) {
    return httpInstance({
        url: '/user/update',
        method: 'PUT',
        data
    })
}

//获取新的用户信息
export function newUserInfoAPI() {
    return httpInstance({
        url: '/user/userInfo'
    })
}

//修改用户头像
export function useUpdateAvatarAPI(avatarUrl) {
    return httpInstance({
        url: '/user/updateAvatar',
        method: 'Patch',
        params: {
            avatarUrl
        }
    })
}

//修改用户密码
export function updatePasswordAPI(data) {
    return httpInstance({
        url: '/user/updatePwd',
        method: 'Patch',
        data
    })
}